<template>
  <div class="components-container">
    <sweet-modal ref="dialog" class="dialog" :sweetModalMaxWidth="pageWidth">
      <h3>{{title}}</h3>
      <div style="max-height:650px;overflow:auto;">
        <fieldset class="layui-elem-field layui-field-title">
          <legend>死者信息</legend>
            <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">逝者姓名</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGNAME"></el-input>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">逝者性别</label>
                  <div class="layui-input-inline">
                    <el-select v-model="regData.REGSEX">
                      <el-option v-for="item in xblx" :key="item.CODNAME" :label="item.CODALIAS" :value="item.CODNAME">
                      </el-option>
                    </el-select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">逝者年龄</label>
                  <div class="layui-input-inline">
                    <el-input-number v-model="regData.REGAGE" :min="0"></el-input-number>
                   </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">逝者类型</label>
                  <div class="layui-input-inline">
                  <el-select v-model="regData.REGBONETYPE">
                    <el-option v-for="item in szlx" :key="item.CODNAME" :label="item.CODALIAS" :value="item.CODNAME">
                    </el-option>
                  </el-select>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">接尸时间</label>
                  <div class="layui-input-inline">
                   <el-date-picker v-date type="datetime" placeholder="选择日期时间" v-model="regDataEexend.regDataTime"></el-date-picker>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">死亡原因</label>
                  <div class="layui-input-inline">
                    <el-cascader :options="cause" v-model="cauinfo" filterable>
                    </el-cascader>
                  </div>
                </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">接运地点</label>
                <div class="layui-input-inline">
                  <input type="text" class="form-control longertext" v-model="regData.REGADDRESS">
                </div>
              </div>
            </div>
         <fieldset class="layui-elem-field layui-field-title">
          <legend>冷藏信息</legend>
        </fieldset>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">冰箱号</label>
                <div class="layui-input-inline">
                  <el-select v-model="regData.REGGHQX">
                    <el-option :key="item.CODNAME" :label="item.CODALIAS" :value="item.CODNAME" v-for="item in ghqx"></el-option>
                  </el-select>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">服务方式</label>
                <div class="layui-input-inline">
                    <el-select v-model="regData.REGYITIQX">
                   <el-option :key="item.CodeValue" :label="item.CodeName" :value="item.CodeValue" v-for="item in serviceListType"></el-option>
                  </el-select>
                </div>
              </div>

            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">接尸车辆</label>
                <div class="layui-input-inline">
                  <el-cascader :options="carLics" v-model="regData.REGCLXX"  filterable clearable>
                  </el-cascader>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">里程数</label>
                <div class="layui-input-inline">
                  <el-input-number v-model="regData.REGLCS" :min="0" style="width:150px"></el-input-number>公里
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">驾驶员</label>
                <div class="layui-input-inline">
                <el-select v-model="regData.REGJSY">
                  <el-option v-for="item in drivers" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
                </div>
              </div>

            </div>

        </fieldset>

        <fieldset class="layui-elem-field layui-field-title">
          <legend>家属信息</legend>
          <div class="layui-field-box">
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">家属姓名</label>
                <div class="layui-input-inline">
                  <input type="text" class="form-control" v-model="regData.REGHANDLERNAME">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">家属性别</label>
                <div class="layui-input-inline">
                  <el-select v-model="regData.REGHANDSEX">
                    <el-option v-for="item in xblx" :key="item.CODNAME" :label="item.CODALIAS" :value="item.CODNAME">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-inline">
                  <input type="text" class="form-control" v-model="regData.REGHANDLERLINK">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">证件类型</label>
                <div class="layui-input-inline">
                  <el-select v-model="regData.REGHANDLERCARDTYPE">
                    <el-option v-for="item in sfzjlx" :key="item.CODNAME" :label="item.CODALIAS" :value="item.CODNAME">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">证件号码</label>
                <div class="layui-input-inline">
                  <input type="text" class="form-control" v-model="regData.REGHANDLERCARDNO">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">逝者关系</label>
                <div class="layui-input-inline">
                  <input type="text" class="form-control" v-model="regData.REGRELATION">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">详细地址</label>
                <div class="layui-input-inline">
                  <el-input class="longertext"  :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入内容" v-model="regData.REGHANDLERHOUSEHOLD">
                  </el-input>
                </div>
              </div>
            </div>
          </div>
        </fieldset>
      </div>
      <div class="layui-form-item btnCenter">
        <el-button   @click="closeDialog">取消</el-button>
        <el-button type="primary"  @click="submit">提交</el-button>
      </div>
    </sweet-modal>
    <sweet-modal ref="dialogInfo" class="dialog" :sweetModalMaxWidth="pageWidth">
      <h3>{{title}}</h3>
      <div style="max-height:600px;overflow:auto;">
        <fieldset class="layui-elem-field layui-field-title">
          <legend>基本信息</legend>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">逝者类型</label>
                <div class="layui-input-inline">
                  <el-input v-model="regData.REGBONETYPE"></el-input>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">到馆日期</label>
                <div class="layui-input-inline">
                  <el-date-picker v-date type="datetime"  v-model="regDataEexend.regDataTime"></el-date-picker>
                </div>
              </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">逝者姓名</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGNAME"></el-input>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">逝者性别</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGSEX"></el-input>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">出生日期</label>
                  <div class="layui-input-inline">
                    <el-date-picker v-date type="date" placeholder="选择日期" v-model="regData.REGBIRTHDATE"></el-date-picker>
                  </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">证件类型</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGCARDTYPE"></el-input>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">证件号码</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGCARDNO"></el-input>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">逝者年龄</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGAGE"></el-input>
                   </div>
                </div>
            </div>
            <div class="layui-form-item">
               <div class="layui-inline">
                  <label class="layui-form-label">死亡日期</label>
                  <div class="layui-input-inline">
                    <el-date-picker v-date type="date"  v-model="regData.REGDEATHDATE"></el-date-picker>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">死亡原因</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGCARDNO"></el-input>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">火化日期</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGAGE"></el-input>
                   </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">民族</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGNATION"></el-input>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">户籍类别</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGHOUSEHOLDTYPE"></el-input>
                  </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">户籍类型</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGHOUSETYPE"></el-input>
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label">户籍地址</label>
                  <div class="layui-input-inline">
                    <!-- <el-input v-model="household"></el-input> -->
                  </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">详细地址</label>
                  <div class="layui-input-inline">
                    <el-input class="longertext"
                       v-model="regData.REGDETAILADDRESS">
                    </el-input>
                  </div>
              </div>
            </div>
         <fieldset class="layui-elem-field layui-field-title">
          <legend>其他信息</legend>
        </fieldset>
            <div class="layui-form-item">
              <div class="layui-inline">
                  <label class="layui-form-label">减免类型</label>
                  <div class="layui-input-inline">
                    <el-input v-model="regData.REGISKEYPOINT"></el-input>
                  </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">骨灰去向</label>
                <div class="layui-input-inline">
                  <el-input v-model="regData.REGGHQX"></el-input>
                </div>
              </div>

            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">炉子类型</label>
                <div class="layui-input-inline">
                  <input type="text" class="form-control" v-model="regData.REGDEATHADDRESS">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">车辆信息</label>
                <div class="layui-input-inline">
                  <input type="text" class="form-control" v-model="regData.REGDEATHADDRESS">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">冰柜编号</label>
                <div class="layui-input-inline">
                  <input type="text" class="form-control" v-model="regData.REGDEATHADDRESS">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">接运地点</label>
                <div class="layui-input-inline">
                  <input type="text" class="form-control longertext" v-model="regData.REGADDRESS">
                </div>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-inline">
                <label class="layui-form-label">详细地址</label>
                <div class="layui-input-inline">
                  <input type="text" class="form-control longertext" v-model="regData.REGDEATHADDRESS">
                </div>
              </div>
            </div>

        </fieldset>
      </div>
      <div class="layui-form-item btnCenter sweet-btn">
        <el-button  @click="closeDialog">取消</el-button>
        <el-button type="primary"  @click="submit">提交</el-button>
      </div>
    </sweet-modal>
  </div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.longtext {
  width: 480px;
}
.longertext {
  width: 770px;
}
.sweet-btn {
  margin-top: 20px;
}
</style>
<script>
import apiBase from "@/api/apiBase.js";
import { ORDER } from "@/const/orderConst.js";
import {
  formatDate,
  timeStringToDate,
  dateStringToDate
} from "@/utils/date.js";
import sweetModal from "@/components/sweetModal";
export default {
  name: "cresimpleReg",
  data() {
    return {
      //户籍所在地
      title: null,
      order: null,
      pageWidth: 1100,
      szlx: [],
      cause: [],
      cauinfo: [],
      icelist: [],
      regData: {
        REGID: null,
        REGPRPID: null,
        REGDATE: null,
        REGTIME: null,
        REGBONETYPE: null,
        REGCAUSA: null,
        REGCAUSASON: null,
        REGADDRESS: null,
        REGYITIQX: null,
        REGNAME: null,
        REGSEX: null,
        REGAGE: null
      },
      ichdata: {
        ICHICEID: null,
        ICHSTADATE: null,
        ICHSTATIME: null
      },
      regDataEexend: {
        regDataTime: null,
      }
    };
  },
  methods: {
    //获取编码
    getCode() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Registration.QueryAllCode,
        res => {
          this.codeList = res.data.content;
          for (var i in this.codeList) {
            switch (this.codeList[i].CTPID) {
              case "逝者类型":
                this.szlx = this.codeList[i].Cods;
                break;
              default:
            }
          }
        }
      );
    },
    //获取死亡原因
    getCausa() {
      let data = {};
      apiBase.DoService(data, apiBase.getApiAdress().Code.GetCausa, res => {
        let caudata = res.data.content;
        this.cause = caudata.map(item => ({
          label: item.CAENAME,
          value: item.CAEID,
          children: item.Caus.map(itemCau => ({
            label: itemCau.CAUNAME,
            value: itemCau.CAUID
          }))
        }));
      });
    },

    //获取预约信息
    getReserveInfo(id) {
      let data = {
        PRPID: id
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Reserve.DetailPhoneReserve,
        res => {
          let resdata = res.data.content;
          this.regData.REGHANDLERNAME = resdata.PRPLINKMAN;
          this.regData.REGNAME = resdata.PRPDEADNAME;
          this.regData.REGPRPID = resdata.PRPID;
          this.regData.REGADDRESS = resdata.PRPCORPSEADDRESS;
          this.regData.REGHANDLERLINK = resdata.PRPLINKPHONE;
          this.regData.REGYITIQX = resdata.PRPYITIQX;
        }
      );
    },
    //获取冰柜信息
    getIce() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ice.QueryIceByIceArea,
        res => {
          let icedata = res.data.content;
          let IceData = icedata.map(item => ({
            label: item.ICANAME,
            value: item.ICAID,
            children: item.list_Ices.map(iceitem => ({
              label: iceitem.ICENO,
              value: iceitem.ICEID
            }))
          }));
          this.icelist = IceData;
        }
      );
    },
    //初始化下拉框数据
    initSelectData() {
      //初始化下拉框数据
      this.getCode();
      this.getCausa();
      this.getIce();
    },
    //打开页面
    open(order, id) {
      this.order = order;

      //清理数据
      this.dataRepeat();
      switch (this.order) {
        case ORDER.SELFREGISTER:
          this.title = "自送登记";
          this.initSelectData();
          this.$refs.dialog.open();
          break;
        case ORDER.REGISTER:
          this.title = "到馆登记";
          this.initSelectData();
          this.$refs.dialog.open();
          this.getReserveInfo(id);
          break;
        case ORDER.MODIFY:
          this.$refs.dialog.open();
          this.initSelectData();
          this.title = "冷藏登记修改";
          this.dataInfo(id);
          break;
        case ORDER.INFO:
          this.$refs.dialogInfo.open();
          this.title = "冷藏登记详情";
          this.dataInfo(id);
          break;
        default:
      }
    },
    //提交
    submit() {
      switch (this.order) {
        case ORDER.SELFREGISTER:
        case ORDER.REGISTER:
          this.dataAdd();
          break;
        case ORDER.MODIFY:
          this.dataModify();
          break;
        case ORDER.DELETE:
          break;
        case ORDER.INFO:
          break;
        default:
      }
    },
    closeDialog() {
      if (
        this.order === ORDER.SELFREGISTER ||
        this.order === ORDER.REGISTER ||
        this.order === ORDER.MODIFY
      )
        this.$refs.dialog.close();
      else if (this.order === INFO) this.$refs.dialogInfo.close();
    },
    //登记新增
    dataAdd() {
      let data = JSON.parse(JSON.stringify(this.regData));
      data.REGCAUSA = this.cauinfo[0];
      data.REGCAUSASON = this.cauinfo[1];
      data.REGHOUSEHOLD = this.ctyLists[2];
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Registration.CremationRegistration,
        res => {
          this.closeDialog();
          this.$message({
            type: "success",
            message: "登记成功!"
          });
          this.loading = false;
          this.getData();
        }
      );
    },
    //登记修改
    dataModify() {
      let data = JSON.parse(JSON.stringify(this.regData));
      data.REGCAUSA = this.cauinfo[0];
      data.REGCAUSASON = this.cauinfo[1];
      data.REGHOUSEHOLD = this.ctyLists[2];
      this.loading = true;
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Registration.ModifyCremationRegistration,
        res => {
          this.closeDialog();
          this.$message({
            type: "success",
            message: "修改成功!"
          });
          this.loading = false;
          this.getData();
        },
        res => {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
      );
    },
    //登记详情
    dataInfo(id) {
      let data = {
        REGID: id
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Registration.DetailCremationRegistration,
        res => {
          this.regData = res.data.content;
          this.regDataEexend.regDataTime = timeStringToDate(
            this.regData.REGTIME,
            this.regData.REGDATE
          );
          this.regDataEexend.regDeathDate = dateStringToDate(
            this.regData.REGDEATHDATE
          );
          this.regDataEexend.RegBirthDate = dateStringToDate(
            this.regData.REGBIRTHDATE
          );
          //初始化死亡原因
          this.cauinfo = [this.regData.REGCAUSA, this.regData.REGCAUSASON];
          this.getHouseholdInfo(this.regData.REGHOUSEHOLD);
        }
      );
    },
    refreshData() {
      this.$emit("refreshData");
    },
    //数据重置
    dataRepeat() {
      Object.assign(this.$data.regData, this.$options.data().regData);
      Object.assign(
        this.$data.regDataEexend,
        this.$options.data().regDataEexend
      );
      this.regDataEexend.regDataTime = new Date();
      this.causList = [];
      this.ctyLists = [];
      this.cauinfo = [];
    }
  },
  components: {
    sweetModal
  },
  computed: {},
  created() {},
  watch: {
    "regDataEexend.regDataTime": function(val) {
      this.regData.REGDATE = formatDate(val, "yyyyMMdd");
      this.regData.REGTIME = formatDate(val, "hhmmss");
    },
  }
};
</script>
